package app.service.domain;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.keter.framework.core.result.JSONResult;
import com.keter.framework.web.annotation.Sid;
import com.keter.framework.web.base.AbstractBaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.Map;

@RestController
public class IndexController extends AbstractBaseController {
	private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

	@GetMapping("/")
	public JSONResult haha() {
		System.out.println(Org.daox.findAll());
		return wrap("haha");
	}

	@GetMapping("/haha")
	@Validated
	public JSONResult haha(@RequestParam("a") @Min(10) @Max(100) int a, @NotEmpty String s) {
		return wrap("haha");
	}

	@GetMapping("/list")
	public JSONResult list() {
		List<Map> list = Lists.newArrayList();
		Map a = Maps.newHashMap();
		a.put("id",1);
		a.put("name","haha");
		Map b = Maps.newHashMap();
		b.put("id",1);
		b.put("name","haha");
		list.add(b);
		return wrap(list);
	}

	@GetMapping("/validate")
	@Validated
	public JSONResult validate(@RequestParam("a") @Min(10) @Max(100) int a, @NotEmpty String s) {
		return wrap("haha");
	}

	/**
	 * 测试框架自动添加的SID
	 * @return
	 */
	@GetMapping(value = "/sid")
	public JSONResult sid(@Sid Long sid) {
		return  wrap(sid);
	}

	@GetMapping(value = "/empty")
	public JSONResult empty() {
		return  wrap(null);
	}
}
